<template>
  <div class="index">
    <div id="login">
      <Card>
        <p slot="title">城市宝藏活动核销管理</p>
        <Alert type="error" show-icon v-if="!existx_activity">该活动不存在</Alert>
        <Form>
          <FormItem class="form-item" label="账号" prop="account">
            <Input v-model="account" type="text" placeholder="请输入登录账号" :disabled="!existx_activity"></Input>
          </FormItem>
          <FormItem class="form-item" label="密码" prop="account">
            <Input v-model="password" type="password" placeholder="请输入登录密码" :disabled="!existx_activity"></Input>
          </FormItem>
          <Button type="success" :loading="login_loading" long v-on:click="login">登录</Button>
        </Form>
      </Card>
    </div>
  </div>
</template>

<script>
import Common from '../../common/common.js';
export default {
  name: 'index',
  data(){
    return {
      //--公共--
      session:{},  //登录信息
      account:'',  //登录账号
      password:'',  //登录密码
      login_loading:false,  //登录请求状态
      //--参数--
      activity_id:0,  //活动id
      //--数据--
      existx_activity:true
    }
  },
  created(){
    this.activity_id = sysinfo.activity_id;
    this.checkActivity();
  },
  methods:{
    //登录
    login(){
      if(!this.loginCheck()) return;
      this.login_loading = true;
      Axios.post(sysinfo.url,Qs.stringify({
          pages:'admin',
          doing:'login',
          activity_id:this.activity_id,
          account:this.account,
          password:this.password
      }))
              .then((res)=>{
                  var data = res.data;
                  this.login_loading = false;
                  if(data.status == 'success'){
                    this.$router.push({name:'home'});
                  }else{
                    this.$Message.error(data.err_msg);
                  }
              })
              .catch(error=>console.log(error));
    },
    //登录验证
    loginCheck(){
      if(this.account == ''){
        this.$Message.error('请输入账号');
        return false;
      }
      if(this.password.length < 6){
        this.$Message.error('请输入正确的密码');
        return false;
      }
      return true;
    },
    //验证活动状态
    checkActivity(){
      Common.checkActivity(this.activity_id,(res)=>{
        if(!res) this.existx_activity = false;
      });
    }
  }
}
</script>

<style scoped>
  .index{
    height:100%;
    background:#2D8CF0;
  }
  #login{
    position: relative;
    top:50%;
    transform: translateY(-50%);
    -ms-transform: translateY(-50%);
    -moz-transform: translateY(-50%);
    -webkit-transform: translateY(-50%);
    -o-transform: translateY(-50%);
    width:450px;
    margin:0 auto;
  }
  .form-item{
    margin-bottom:10px;
  }
</style>
